package de.java.shortys.utils.type;

import java.util.Calendar;
import java.util.Date;

public final class CalendarUtils {

	public static Calendar toCalendar(int date, int month, int year) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.DATE, date);
		calendar.set(Calendar.MONTH, month + 1);
		calendar.set(Calendar.YEAR, year);
		clearTimeInfo(calendar);
		return calendar;
	}

	public static Calendar toCalendar(int date, int month, int year, int hour, int minute) {
		Calendar calendar = toCalendar(date, month, year);
		calendar.set(Calendar.HOUR, hour);
		calendar.set(Calendar.MINUTE, minute);
		calendar.clear(Calendar.SECOND);
		calendar.clear(Calendar.MILLISECOND);
		return calendar;
	}

	public static Calendar toCalendar(int date, int month, int year, int hour, int minute, int second) {
		Calendar calendar = toCalendar(date, month, year, hour, minute);
		calendar.set(Calendar.SECOND, second);
		calendar.clear(Calendar.MILLISECOND);
		return calendar;
	}

	public static Calendar toCalendar(int date, int month, int year, int hour, int minute, int second, int millisecond) {
		Calendar calendar = toCalendar(date, month, year, hour, minute, second);
		calendar.set(Calendar.MILLISECOND, millisecond);
		return calendar;
	}

	public static Calendar toCalendar(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar;
	}

	public static void clearTimeInfo(Calendar calendar) {
		calendar.clear(Calendar.HOUR);
		calendar.clear(Calendar.MINUTE);
		calendar.clear(Calendar.SECOND);
		calendar.clear(Calendar.MILLISECOND);
	}

	private CalendarUtils() {
		// Empty
	}
}
